<?php
class home extends serviceAdminBase {
    function __construct() {
        parent::__construct();
        $this->cms->setPageTitle("管理面板");
    }

    function indexTask(){
        $this->cms->setActionTitle("概要总览");
        $db=SqlDB::init();
        $user_info = $this->user->getLoginInfo();
        $service_id = ServiceMode::init()->getServiceId($user_info['id']);
        //获取总成交量
        $result['order_total']=$db->getValue("SELECT sum(`order_amount`) FROM `order` where `state`<>'unpaid' and `service_id`=$service_id");
        //获取本月交易额
        $todayDate=date("Y-m-d");
        $beginDate=date('Y-m-d', mktime(0,0,0,date('n'),1,date('Y')));
        if($todayDate==$beginDate){
            $days = 1;
        }else{
            $days=round((strtotime($todayDate)-strtotime($beginDate))/3600/24);
        }
        $sql="SELECT sum(`order_amount`) FROM `order` where `payment_time`>=? and `payment_time`<? and `service_id`=$service_id";
        $result['this_month']=$db->getValue($sql,$beginDate,$todayDate);
        //获取本月日均交易额
        $result['average_month']=round($result['this_month']/$days,2);
        //获取当日交易额
        $tomorrowDate=date("Y-m-d",strtotime("+1 day"));
        $result['order_today']=$db->getValue($sql, $todayDate, $tomorrowDate);
        $this->cms->tableScene($result,"service/index.php");
    }

    function serviceInfoTask(){
        $user_info=$this->user->getLoginInfo();
        $service=ServiceMode::init();
        $serviceId=$service->getServiceId($user_info['id']);
        $r=$service->getDetail($serviceId);
        $address=AddressMode::init();
        $r['address_id']=$address->getDetailAsString($r['address_id']);
        $pic=PictureModule::init('picture');
        $idnum_pic=$pic->getDetail($r['idnum_pic']);
        $r['idnum_pic']=!empty($idnum_pic)?$idnum_pic:'upload/thumb.jpg';
        $facade_pic=$pic->getDetail($r['facade_pic']);
        $r['facade_pic']=!empty($facade_pic)?$facade_pic:'upload/thumb.jpg';
        $this->cms->tableScene($r,"service/service_info.php");
    }
}